package com.shuyuansystem.service.impl;

import com.shuyuansystem.dao.OrderInfoMapper;
import com.shuyuansystem.pojo.OrderInfo;
import com.shuyuansystem.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    // 根据id获取商家订单
    @Override
    public List<OrderInfo> getOrderInfoByUserId(String userId) {
        return orderInfoMapper.getOrderInfoByMerchantId(userId);
    }

    @Override
    public boolean updateOrderStatusToProducing(String merchantOrderNumber) {
        int rowsAffected = orderInfoMapper.updateOrderStatusToProducing(merchantOrderNumber);
        return rowsAffected > 0;
    }

    @Override
    public boolean updateVideoUrl(String orderNumber, String videoUrl) {
        try {
            int rowAffected = orderInfoMapper.updateVideoUrl(orderNumber, videoUrl);
            return rowAffected > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    @Override
    public boolean updateTransactionStatusToShipping(String orderNumber) {
        try {
            // 调用OrderInfoMapper中的方法更新交易状态
            int rowAffected = orderInfoMapper.updateTransactionStatusToShipping(orderNumber);
            return rowAffected > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
}

    @Override
    public boolean updateOrderStatusToCompleted(String orderNumber) {
        try {
            int rowsAffected = orderInfoMapper.updateOrderStatusToCompleted(orderNumber);
            return rowsAffected > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public List<OrderInfo> getAllByUserId(String userId) {
        return orderInfoMapper.getAllByUserId(userId);
    }

    @Override
    public boolean cancelOrder(String merchantOrderNumber) {
        try {
            // 调用 OrderInfoMapper 中的方法删除订单信息
            int rowAffected = orderInfoMapper.deleteByMerchantOrderNumber(merchantOrderNumber);
            return rowAffected > 0;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public void updateOrderStatusRefundOrder(OrderInfo orderInfo) {

    }

    @Override
    public List<OrderInfo> getAllByMerchantId(String MerchantId) {
        return orderInfoMapper.getAllByMerchantId(MerchantId);
    }
    @Override
    public List<String> getVideoUrlsByMerchantOrderNumber(String MerchantOrderNumber) {
        return orderInfoMapper.getVideoUrlsByMerchantOrderNumber(MerchantOrderNumber);
    }

}